package com.shopping.servlet.order;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSONObject;
import com.shopping.service.OrderService;
import com.shopping.service.impl.OrderServiceImpl;

@WebServlet("/DeleteOrderServlet")
public class DeleteOrderServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    public DeleteOrderServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.getWriter().append("Served at: ").append(request.getContextPath());
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("application/json;charset=utf-8");
		PrintWriter out = response.getWriter();

		long id = Long.parseLong(request.getParameter("o_id"));

		OrderService os = new OrderServiceImpl();
		boolean b = os.deleteOrder(id);
		JSONObject jo = new JSONObject();
		if(b==true) {
			jo.put("code", 0);
			jo.put("msg",id);
		}
		else {
			jo.put("code", 1);
			jo.put("msg", id);
		}
		jo.put("count", 1);
		
		System.out.println(jo);
		out.print(jo);	
	}

}
